import dt from '@dt/dt'
import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'
import productOpt from '@/biz/option/product.js'

function options(_this, type = 0) { // 0 选择 1 弹框 2 明细
  let check = type == 1 ? [{
    type: 'checkbox',
    minWidth: 50
  }] : []

  let handle = type == 0 ? [{
    field: 'handles',
    title: '操作',
    width: 80,
    fixed: 'right',
    slots: {
      default: (params, h) => {
        return table.cell.btn(_this, h, {
          title: '删除',
          event: 'onDelete',
          data: params.row
        })
      }
    }
  }] : []

  return [
    ...check,
    {
      type: 'index',
      title: '序号',
      minWidth: 50
    },
    {
      field: 'roomName',
      title: '房源名称',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: params.row.roomName
          })
        }
      }
    },
    {
      field: 'commissionOrderStatusStr',
      minWidth: 100,
      title: '房源状态',
      slots: type == 1 ? {} : {
        header: (params, h) => {
          return table.header.arrow(_this, h, {
            title: '房源状态',
            key: 'commissionOrderStatus',
            placeholder: '请选择房源状态',
            select: {
              options: dt.dictInfo().commissionOrderStatus
            }
          })
        }
      }
    },
    {
      field: 'contractDate',
      minWidth: 150,
      title: '签约日期',
      slots: type == 1 ? {} : {
        header: (params, h) => {
          return table.header.arrow(_this, h, {
            title: '签约日期',
            key: 'contractDate',
            placeholder: '请选择签约日期',
            date: {
              type: 'daterange'
            },
            data: {
              to: (val) => {
                return {
                  contractStartDate: val[0],
                  contractEndDate: val[1]
                }
              }
            }
          })
        }
      }
    },
    {
      field: 'customerName',
      minWidth: 150,
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, {
            title: '客户姓名',
            key: 'customerName',
            placeholder: '请输入客户姓名',
            input: {},
          })
        }
      }
    },
    {
      field: 'productName',
      title: '产品',
      minWidth: 150,
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, productOpt.create({
            key: 'productId'
          }))
        },
        default: (params, h) => {
          return table.cell.text(h, {
            value: params.row.productName
          })
        }
      }
    },
    {
      field: 'counselorName',
      minWidth: 100,
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, nameOpt.create({
            key: 'counselorId',
            title: '业务员'
          }))
        }
      }
    },
    {
      field: 'channelSourceName',
      title: '渠道来源',
      minWidth: 120,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: params.row.channelSourceName
          })
        }
      }
    },
    {
      field: 'isAssociatesStr',
      minWidth: 100,
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, {
            title: '关系户',
            key: 'isAssociates',
            placeholder: '请选择是否关系户',
            select: {
              options: [{
                key: 1,
                value: '是'
              }, {
                key: 0,
                value: '否'
              }]
            }
          })
        }
      }
    },
    {
      field: 'isInsteadOfWorkersStr',
      minWidth: 100,
      slots: {
        header: (params, h) => {
          return table.header.arrow(_this, h, {
            title: '联代分佣',
            key: 'isInsteadOfWorkers',
            placeholder: '请选择是否联代分佣',
            select: {
              options: [{
                key: 1,
                value: '是'
              }, {
                key: 0,
                value: '否'
              }]
            }
          })
        }
      }
    },
    {
      field: 'area',
      title: '面积(m²)',
      minWidth: 100,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: dt.tool.formatterMoney(params.row.area)
          })
        }
      }
    },
    {
      field: 'unitPrice',
      title: '签约单价(元)',
      minWidth: 130,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: dt.tool.formatterMoney(params.row.unitPrice)
          })
        }
      }
    },
    {
      field: 'basicTotalPrice',
      title: '底总价(元)',
      minWidth: 100,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: dt.tool.formatterMoney(params.row.basicTotalPrice)
          })
        }
      }
    },
    {
      field: 'totalPrice',
      title: '签约总价(元)',
      minWidth: 130,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: dt.tool.formatterMoney(params.row.totalPrice)
          })
        }
      }
    },
    {
      field: 'predictAccountDate',
      minWidth: 150,
      title: '全款到账日期',
      slots: type == 1 ? {} : {
        header: (params, h) => {
          return table.header.arrow(_this, h, {
            title: '全款到账日期',
            key: 'predictAccountDate',
            placeholder: '请选择全款到账日期',
            date: {
              type: 'daterange'
            },
            data: {
              from: (info) => {
                if (info.accountDateStart) {
                  return [info.accountDateStart, info.accountDateEnd]
                }
              },
              to: (val) => {
                return {
                  accountDateStart: val[0],
                  accountDateEnd: val[1]
                }
              }
            }
          })
        }
      }
    },
    {
      field: 'accumulateMoney',
      title: '累计回款金额(元)',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: dt.tool.formatterMoney(params.row.accumulateMoney)
          })
        }
      }
    },
    {
      field: 'settlementTotalSales',
      title: '已结算总销(元)',
      minWidth: 130,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: dt.tool.formatterMoney(params.row.settlementTotalSales)
          })
        }
      }
    },
    {
      field: 'settledAgentCost',
      title: '已结算结代理费(元)',
      minWidth: 150,
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: dt.tool.formatterMoney(params.row.settledAgentCost)
          })
        }
      }
    },
    ...handle
  ]
}

export default {
  options
}